#include "MenuManager.h"
#include <sqlite3.h>
#include <sstream>
#include "Logger.h"
#include "Constants.h"
#include "Game.h"

using namespace std;

// OnClick callback functions

void onClick_continue(MenuItem* MItem) {
	MessageBox(NULL, L"Test", L"Test", MB_OK | MB_ICONINFORMATION);
}

void onClick_exit(MenuItem* MItem) {
	
}

MenuManager::MenuManager() {

};

MenuManager::~MenuManager() {
	
	for(unsigned int i = 0; i < this->MenuItemPtrs.size(); i++) {
		if(this->MenuItemPtrs[i] != NULL) delete this->MenuItemPtrs[i];
	}
}

int MenuManager::Initialize() {

	// Create all menu items here

	this->MenuItemPtrs.push_back(new MenuItem("mainmenu", windowSize.right, windowSize.bottom, 0.0f, 0.0f, 0, "", NULL)); // Menu background
	this->MenuItemPtrs[this->MenuItemPtrs.size()-1]->SetColor(D3DXCOLOR(0.2f, 0.2f, 0.2f, 0.8f));

	this->MenuItemPtrs.push_back(new MenuItem("mainmenu", 500, 100, 0.47f, -1.0f, 1, "Continue", onClick_continue));
	this->MenuItemPtrs[this->MenuItemPtrs.size()-1]->SetColor(D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f));

	this->MenuItemPtrs.push_back(new MenuItem("mainmenu", 500, 100, 0.6f, -1.0f, 1, "Exit", onClick_exit));
	this->MenuItemPtrs[this->MenuItemPtrs.size()-1]->SetColor(D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));

	return 0;
	
}

void MenuManager::ShowMenu(string menuGroup) {

	for(unsigned int i = 0; i < this->MenuItemPtrs.size(); i++) {
		if(this->MenuItemPtrs[i]->menuGroup.find(menuGroup) != string::npos) this->MenuItemPtrs[i]->SetShowing(true);
		else this->MenuItemPtrs[i]->SetShowing(false);
	}

}